package com.atguigu.eduService.controller.front;

import com.atguigu.commonutils.R;
import com.atguigu.eduService.entity.EduCourse;
import com.atguigu.eduService.entity.EduTeacher;
import com.atguigu.eduService.service.EduCourseService;
import com.atguigu.eduService.service.EduTeacherService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.xml.crypto.Data;
import java.util.List;
import java.util.Map;

/**
 * @author: 亚当
 * @date: 2022年07月11日 10:32
 * @package: com.atguigu.eduService.controller.front
 * @Description: TODO
 */
@RestController
@CrossOrigin
@RequestMapping("/eduService/teacherFront")
public class TeacherFrontController {

    @Autowired
    private EduTeacherService teacherService;
    @Autowired
    private EduCourseService courseService;

    //分页查询讲师的方法
    @PostMapping("getTeachetFrontList/{page}/{limit}")
    public R getTeachetFrontList(@PathVariable Long page,
                             @PathVariable Long limit){
        Page<EduTeacher> eduTeacherPage = new Page<>(page,limit);
        Map<String,Object> map = teacherService.getTeacherFrontList(eduTeacherPage);
        //返回分页所有数据

        return R.ok().data(map);
    }
    //讲师详情的功能
    @ApiOperation("讲师详情的功能")
    @GetMapping("getTeacherFrontInfo/{teacherId}")
    public R getTeacherFrontInfo(@PathVariable String teacherId){
        //1.根据讲师id查询讲师基本信息
        EduTeacher eduTeacher = teacherService.getById(teacherId);
        //2.根据讲师id查询讲师课程
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",teacherId);
        List<EduCourse> eduList = courseService.list(wrapper);
        return R.ok().data("teacher",eduTeacher).data("courseList",eduList);
    }
}
